<?
include("../lib/config.php");
$g	= $HTTP_GET_VARS['g'];
$op	= $HTTP_GET_VARS['op'];

if($op == "edit"){
	$Faction 	= "../lib/update.php";
	$Vbutton 	= "Update";
	$query		= mssql_query("SELECT * FROM S_User_Group A, S_Priv_User B WHERE A.group_id=B.group_id AND A.group_id='$g' ",$conn);
	$row		= mssql_fetch_array($query);
	$readonly 	= "readonly";
}
else{
	$Faction 	= "../lib/save.php";
	$Vbutton 	= "Simpan";
	$readonly 	= "";
}

include("../header.php");
?>
<script type="text/javascript">
	function Validate(){
		if(document.F.group_code.value == "")
		{
			alert("Field : Kode Group tidak boleh kosong dan bernilai unik ...");
			document.F.group_code.focus();
			return false;
		}
		
		if(document.F.group_name.value == "")
		{
			alert("Field : Nama Group tidak boleh kosong dan bernilai unik ...");
			document.F.group_name.focus();
			return false;
		}
		
		document.F.submit();
		
	}
</script>
</head>
<table width="93%" class="table_indent2" class="no_border">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>GROUP USER</b></td>
	</tr>
	<tr>
	</table>
  </td>
  </td>
 </tr>
 <tr>
  <td>
  <form name="F" action="<?=$Faction?>" method="post">
     <table cellpadding="4" cellspacing="1" width="100%">
      <tr>
       <td>Kode Group:</td>
       <td><input type="text" name="group_code" value="<?=$row[group_id]?>" <?=$readonly?> /> <span class="required">*</span></td>
      </tr>
      <tr>
       <td>Nama Group:</td>
       <td><input type="text" name="group_name" value="<?=$row[group_name]?>" /> <span class="required">*</span></td>
      </tr>
      <tr>
       <td valign="top">Keterangan:</td>
       <td valign="top"><textarea cols="35" rows="1" name="keterangan"><?=$row[note]?></textarea></td>
      </tr>
      <tr>
       <td colspan="2"><hr noshade="noshade" size="-2" /></td>
      </tr>
      <tr>
       <td colspan="2">
       <fieldset><legend>Hak Akses</legend>
        <table cellpadding="1" cellspacing="1" width="100%">
         <tr class="headlist">
		  <td width="2%" rowspan="2">&nbsp;</td>
          <td rowspan="2">Nama Menu</td>
          <td colspan="5">Hak Akses</td>
         </tr>
		 <tr class="headlist">
		  <td width="100">Read Only</td>
		  <td width="100">Tambah</td>
		  <td width="100">Edit</td>
		  <td width="100">Delete</td>
		  <td width="100">Approval</td>		  		  		  		  
		 </tr>
<?
	for($i=0;$i<17;$i++){
//	echo"$rsql[nama_menu] <br>";
?>
         <tr bgcolor="#F2F9FF">
          <td align="center">&bull;</td>
          <td>
          <?
          // title
		  switch($i)
		  {
		  case 0:
		  	echo"KELUARGA";
			$menuname = "keluarga";
			break;
		  case 1;
		  	echo"CUTI";
			$menuname = "cuti";			
			break;
		  case 2;
		  	echo"MEDICAL";
			$menuname = "medical";			
			break;
		  case 3;
		  	echo"KARIR PTSI";
			$menuname = "karir_ptsi";			
			break;
		  case 4;
		  	echo"SANKSI";
			$menuname = "sanksi";			
			break;
		  case 5;
		  	echo"TRACK RECORD";
			$menuname = "track_record";			
			break;
		  case 6;
		  	echo"PENUGASAN";
			$menuname = "penugasan";			
			break;
		  case 7;
		  	echo"PENILAIAN";
			$menuname = "penilaian";			
			break;
		  case 8;
		  	echo"SETUP MEDICAL";
			$menuname = "setup_medical";
			break;
		  case 9;
		  	echo"PARAMETER DATA";
			$menuname = "parameter_data";			
			break;
		  case 10;
		  	echo"ADMINISTRASI USER";
			$menuname = "administrasi_user";			
			break;
		  case 11;
		  	echo"REPORT";
			$menuname = "report";			
			break;
		  case 12;
		  	echo"CV ONLINE";
			$menuname = "cvonline";			
			break;
		  case 13;
		  	echo"MASTER KARYAWAN";
			$menuname = "master_karyawan";
			break;			
		  case 14;
		  	echo"UPLOAD DOCUMENT";
			$menuname = "upload_document";
			break;			
		  case 15;
		  	echo"DOWNLOAD DOCUMENT";
			$menuname = "download_document";
			break;
		  case 16;
		  	echo"ADM RESET PASSWORD";
			$menuname = "adm_reset_password";
			break;
		  }	
	$qsql 	= mssql_query("WITH AYE AS (SELECT ROW_NUMBER() OVER (ORDER BY group_id) AS No, * FROM S_Priv_User WHERE group_id='".$row[group_id]."') SELECT * FROM AYE WHERE No='".($i+1)."'",$conn);
	$rsql	= mssql_fetch_array($qsql);
//	echo"$rsql[nama_menu]";
		  ?>
          </td>
          <td align="center" width="50">
          <input type="hidden" name="menuname[]" value="<?=$menuname?>" />
		  <input type="checkbox" name="view_<?=$menuname?>" 
		  <? if($rsql[baca] == 1 && $rsql[nama_menu] == $menuname){ echo"checked";} ?> value="1" <? if($op==""){echo"checked";} ?> /> 
		  </td>
		  <td align="center" width="50">
		  <input type="checkbox" name="add_<?=$menuname?>" value="1" <? if($rsql[tambah] == 1 && $rsql[nama_menu] == $menuname){ echo"checked";} ?> /> 
		  </td>
		  <td align="center" width="50">
		  <input type="checkbox" name="edit_<?=$menuname?>" value="1" <? if($rsql[edit] == 1 && $rsql[nama_menu] == $menuname){ echo"checked";} ?> /> 
		  </td>
		  <td align="center" width="50">
		  <input type="checkbox" name="delete_<?=$menuname?>" value="1" <? if($rsql[hapus] == 1 && $rsql[nama_menu] == $menuname){ echo"checked";} ?> /> 
		  </td>
		  <td align="center" width="50">
		  <input type="checkbox" name="approval_<?=$menuname?>" value="1" <? if($rsql[approval] == 1 && $rsql[nama_menu] == $menuname){ echo"checked";} ?> />
          </td>
         </tr>
<?
	}
	echo"
	<tr bgcolor=\"#F2F9FF\">
	 <td colspan=7 align=center>&nbsp;</td>
	</tr>
	<tr bgcolor=\"#F2F9FF\">
	 <td colspan=7 align=center><b>MENU DIBAWAH INI KHUSUS ADUM (CABANG &amp; SBU)</b></td>
	</tr>
	<tr class=\"headlist\">
	 <td>&nbsp;</td>
	 <td colspan=2><b>Cabang/SBU</b></td>
	 <td colspan=4><b>Akses<b> (Checklist = Ya)</td>
	</tr>
	";
	// get cabang untuk ADUM
	$sad = mssql_query("select * from vcabang",$conn);
	while($rad = mssql_fetch_array($sad)){
	
	$qsqlv 	= mssql_query("SELECT * FROM S_Priv_User WHERE group_id='".$row[group_id]."' AND nama_menu='".$rad[2]."'",$conn);
	$rsqlv	= mssql_fetch_array($qsqlv);

		echo"
		<tr bgcolor=\"#F2F9FF\">
		 <td align=\"center\">&bull;</td>
		 <td colspan=2>$rad[1] - $rad[2]</td>";
?>		 
          <td align="center" width="50" colspan="4">
          <input type="hidden" name="menuname[]" value="<?=$rad[2]?>" />
		  <input type="checkbox" name="view_<?=$rad[2]?>" 
		  <? if($rad[2] == $rsqlv['nama_menu'] && $rsqlv[baca] == "1"){ echo"checked";} ?> value="1" /> 
		  </td>
<?
		echo"
		</tr>
		";
	}
?>
        </table>
        </fieldset>
       </td>
      </tr>
      <tR>
       <td align="center" colspan="4">
       <input type="hidden" name="cat" value="add_group" />
       <input type="button" class="button" onclick="Javascript:history.back();" value="Cancel" />
       <input type="button" class="button" onclick="Validate();" value="<?=$Vbutton?>" /></td>
      </tR>
     </table>
     </form>
  </td>
</tr>
</table>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>